//
//  PGViewController.m
//  PhotographicGuide
//
//  Created by indream on 13-2-6.
//  Copyright (c) 2013年 indream. All rights reserved.
//

#import "PGViewController.h"
#import "PGDetailViewController.h"
#import "PGDeviceTableSource.h"
#import "PGArticleManager.h"
#import "CKRefresh/CKRefreshControl.h"
#import "MobClick.h"

#import "PGTableViewController.h"
#import "PGTopicTableViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface PGViewController ()

@end

@implementation PGViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:YES];
    self.shareView.isDetail = NO;
    PGTableViewController *tableController = [PGTableViewController sharedController];
    tableController.navigationController = self.navigationController;
    self.tableView = tableController.tableView;
    [self.listView addSubview:self.tableView];
    
    PGTopicTableViewController *topicTableController = [PGTopicTableViewController sharedController];
    topicTableController.navigationController = self.navigationController;
    self.topicTableView = topicTableController.tableView;
    self.topicTableView.backgroundColor = [UIColor blackColor];
    self.topicTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.listView addSubview:self.topicTableView];
    CGRect rect = self.listView.frame;
    rect.origin.x = 0.0;
    rect.origin.y = 0.0;
    self.tableView.frame =  rect;
    self.topicTableView.frame =  rect;
    self.tableView.hidden = NO;;
    self.topicTableView.hidden = YES;
    [PGDeviceTableSource sharedSource].navigationController = self.navigationController;
    _segmentId = 0;
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [PGArticleManager sharedManager].currentArticleId = 0;
    [MobClick beginLogPageView:@"Home"];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"Home"];
}
- (void)viewDidUnload {
    [self setImageViewScreen:nil];
    [self setBackgroundViewScreen:nil];
    [self setTableView:nil];
    [self setPhotoButton:nil];
    [self setDeviceButton:nil];
    [self setListView:nil];
    [super viewDidUnload];
}
- (IBAction)openFaverite:(id)sender {
    if(isShowAnimate==NO){
        [self addShareView:0];
    }
}

- (void)segmentChanged {
    if(_segmentId==0){
        self.tableView.hidden = NO;
        self.topicTableView.hidden = YES;
    }else{
        self.tableView.hidden = YES;
        self.topicTableView.hidden = NO;
    }
}

- (IBAction)segmentForPhotoHandle:(id)sender {
    UIButton*button = (UIButton*)sender;
    [button setSelected:YES];
    [button setUserInteractionEnabled:NO];
    
    [_deviceButton setSelected:NO];
    [_deviceButton setUserInteractionEnabled:YES];
    _segmentId = 0;
    [self segmentChanged];
}

- (IBAction)segmentForDeviceHandle:(id)sender {
    UIButton*button = (UIButton*)sender;
    [button setSelected:YES];
    [button setUserInteractionEnabled:NO];
    
    [_photoButton setSelected:NO];
    [_photoButton setUserInteractionEnabled:YES];
    _segmentId = 1;
    [self segmentChanged];
}
@end
